<template>
  <div>
    <div class="formInfo">
      <input
        v-model="form.password"
        class="loginInput"
        type="text"
        password
        placeholder="请输入密码"
        placeholder-class="placeholder-part"
        maxlength="11"
      />
      <button class="btn-color-blue loginBtn" @click="handleClick">下一步</button>
    </div>
    <a class="findPass" href="/pages/open-shop/store-find-pas/main">找回密码</a>
  </div>
</template>

<script>
import { getCurrentPageParams, encryptMD5 } from '@/utils'
import { STORE_CUSTOMER_LOGIN, STORE_CUSTOMER_TOKEN } from '@/api'

export default {
  components: {},
  props: {},
  data () {
    return {
      form: {
        loginName: '',
        password: ''
      }
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  onShow () {},
  methods: {
    handleClick () {
      const vm = this
      if (vm.form.password) {
        vm.form.loginName = getCurrentPageParams('phone')
        vm.customerToken()
      } else {
        vm.$toast('请输入登录密码')
      }
    },
    customerToken () {
      const vm = this
      if (!vm.form.loginName) {
        vm.$toast('无手机号')
        return false
      } else if (!vm.form.password) {
        vm.$toast('无登陆密码')
        return false
      }
      let params = {
        ...vm.form,
        providerId: vm.$store.state.account.providerId,
        appId: 23
      }
      params.password = encryptMD5(vm.form.password)

      STORE_CUSTOMER_TOKEN(params)
        .then(r => {
          if (r.data.code === '0') {
            vm.customerLogin(r.data.data)
          } else {
            vm.$toast(r.data.message)
          }
        })
        .catch(e => {
          console.error(e)
        })
    },

    customerLogin (token) {
      const vm = this

      if (!vm.form.loginName) {
        vm.$toast('请填写手机号')
        return false
      } else if (!vm.form.password) {
        vm.$toast('请填写登录密码')
        return false
      }

      let params = {
        ...vm.form,
        providerId: vm.$store.state.account.providerId,
        source: 'H5',
        token: token
      }
      params.password = encryptMD5(vm.form.password)

      STORE_CUSTOMER_LOGIN(params)
        .then(r => {
          if (r.data.code === '0') {
            let { customerId, mobile } = r.data.data
            // let { mobile } = r.data.data
            // vm.$router.push(
            //   `/pages/open-shop/open-shop-find-list/main?customerId=${customerId}&mobile=${mobile}`
            // )
            vm.$router.push(
              `/pages/new-open-shop/index/main?customerId=${customerId}&mobile=${mobile}`
            )

            // openShopAction(customerId)
            vm.$cookie.set('store-mobile', mobile)
            vm.$cookie.set('store-login', r.data.data)
          } else {
            vm.$toast(r.data.message)
          }
        })
        .catch(e => {
          console.error(e)
        })
    }
  }
}
</script>

<style lang="scss" scoped>
@import 'static/styles/color.scss';
.formInfo {
  width: 90%;
  margin: 50px auto 10px;
  .loginInput {
    font-size: 14px;
    color: #999999;
    border-bottom: 1px solid #e8e8e8;
    padding-right: 3px;
  }
  .loginBtn {
    border-radius: 25px;
    line-height: 40px;
    margin-top: 30px;
    height: 40px;
  }
}
.findPass {
  width: 90%;
  margin: auto;
  display: flex;
  justify-content: flex-end;
  font-size: 14px;
  color: $blue;
}
</style>
